import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false

App.mpType = 'app'
import uView from '@/uni_modules/uview-ui'

Vue.use(uView)
const app = new Vue({
	...App
})
app.$mount()
// let baseUrl = "https://o797g75692.goho.co/api"
// let baseUrl = "http://10.225.30.18:8080/api"
let baseUrl = "https://a5942g1060.zicp.fun/api"

Vue.prototype.code = "1234"
Vue.prototype.tencent = {
	trtc: {
		appid: "APPID"
	} 
}


Vue.prototype.$url = {
	register: baseUrl + "/user/register",
	login: baseUrl + "/user/login",
	getLoginUser: baseUrl + "/user/getLoginUser",
	searchAllActClass: baseUrl + "/actClass/searchAllActClass",
	searchAllShopsByPage: baseUrl + "/shop/searchAllShopsByPage",
	searchShopById: baseUrl + "/shop/searchShopById",
	searchDishesByShopId: baseUrl + "/dish/searchDishesByShopId",
	searchAllComments: baseUrl + "/comment/searchAllComments",
	addThumb: baseUrl + "/thumb/addThumb",
	removeThumb: baseUrl + "/thumb/removeThumb",
	addCollect: baseUrl + "/collect/addCollect",
	removeCollect: baseUrl + "/collect/removeCollect",
	isThumb: baseUrl + "/thumb/isThumb",
	isCollect: baseUrl + "/collect/isCollect",
	addComment: baseUrl + "/comment/addComment",
	deleteMyComment: baseUrl + "/comment/deleteMyComment",
	getTimetable: baseUrl + "/timetable/getTimetable",
	updateUserInfo: baseUrl + "/user/updateUserInfo",
	getAllOperation: baseUrl + "/operation/getAllOperation",
	searchMyCollectList: baseUrl + "/user/searchMyCollectList",
	searchMyThumbList: baseUrl + "/user/searchMyThumbList",
	searchAllPostClass: baseUrl + "/post/searchAllPostClass",
	searchAllPosts: baseUrl + "/post/searchAllPosts",
	actThumbPost: baseUrl + "/post/actThumbPost",
	isThumbPost: baseUrl + "/post/isThumbPost",
	searchAllPostById: baseUrl + "/post/searchAllPostById",
	searchAllPostComments: baseUrl + "/postComment/searchAllComments",
	addPostComment: baseUrl + "/postComment/addComment",
	deleteMyPostComment: baseUrl + "/postComment/deleteMyComment",
	searchTag: baseUrl + "/tag/searchTag",
	addPost: baseUrl + "/post/addPost",
	deletePost: baseUrl + "/post/deletePost",
	upLoad: baseUrl + "/upLoad/upLoad",
	searchPostByTag: baseUrl + "/post/searchPostByTag",
	searchAllRotationChart: baseUrl + "/rotation/searchAllRotationChart",
	touristLogin: baseUrl + "/user/touristLogin",
	sendMessage: baseUrl + "/message/sendMessage",
	getMessage: baseUrl + "/message/getMessage",
	searchMyMessage: baseUrl + "/message/searchMyMessage",
	searchTopCommentById: baseUrl + "/comment/searchTopCommentById",
	searchTopPostCommentById: baseUrl + "/postComment/searchTopPostCommentById",
	updatePassword: baseUrl + "/user/updatePassword",
	searchAllUserByPage: baseUrl + "/user/searchAllUserByPage",
	getUser: baseUrl + "/user/getUser",
	updateUser: baseUrl + "/user/updateUser",
	updateShopById: baseUrl + "/shop/updateShopById",
	deleteUser: baseUrl + "/user/deleteUser",
	deleteShop: baseUrl + "/shop/deleteShop",
	searchAllShops: baseUrl + "/shop/searchAllShops",
	deleteMessage: baseUrl + "/message/deleteMessage",
	searchMyPost: baseUrl + "/post/searchMyPost",
	searchMyPostNum: baseUrl + "/post/searchMyPostNum",
	addRate: baseUrl + "/rate/addRate",
	deleteTimetable: baseUrl + "/timetable/deleteTimetable",
	chat: baseUrl + "/chat/chat",
	searchInfoHistory: baseUrl + "/chat/searchInfoHistory",
	searchMyInfo: baseUrl + "/chat/searchMyInfo",
	searchPrivateChatObject: baseUrl + "/chat/searchPrivateChatObject",
	addShop: baseUrl + "/shop/addShop",
	searchUnCheckShopByPage: baseUrl + "/shop/searchUnCheckShopByPage",
	agreeShop: baseUrl + "/shop/agreeShop",
	searchMyCheckMessage: baseUrl + "/message/searchMyCheckMessage",
	updateShopStatus: baseUrl + "/shop/updateShopStatus",
	addDish: baseUrl + "/dish/addDish",
	addComplaint: baseUrl + "/complaint/addComplaint",
	searchAllMyCheckMessage: baseUrl + "/message/searchAllMyCheckMessage",
	addAdvertisement: baseUrl + "/advertisement/addAdvertisement",
}

Vue.prototype.checkPermission = function(perms) {
	let permission = uni.getStorageSync("permission")
	let result = false
	for (let one of perms) {
		if (permission.indexOf(one) != -1) {
			result = true
			break
		}
	}
	return result
}

// 封装的Ajax请求函数
Vue.prototype.$ajax = function(url, method, data, fun){
	uni.request({
		"url": url,
		"method": method,
		"header": {
			token: uni.getStorageSync('token')
		},
		"data": data,
		success: function(resp) {
			if (resp.statusCode == 401) {
				uni.redirectTo({
					url: '../login/login'
				});
			} else if (resp.statusCode == 200 && resp.data.code == 200) {
				let data = resp.data
				if (data.hasOwnProperty('token')) {
					let token = data.token
					uni.setStorageSync("token", token)
				}
				fun(resp)
			} else {
				uni.showToast({
					icon: 'none',
					title: resp.data
				});
			}
		}
	});
}

Date.prototype.format = function(fmt) {
	var o = {
		"M+": this.getMonth() + 1, //月份 
		"d+": this.getDate(), //日 
		"h+": this.getHours(), //小时 
		"m+": this.getMinutes(), //分 
		"s+": this.getSeconds(), //秒 
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
		"S": this.getMilliseconds() //毫秒 
	};
	if (/(y+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	}
	for (var k in o) {
		if (new RegExp("(" + k + ")").test(fmt)) {
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k])
				.length)));
		}
	}
	return fmt;
}

Vue.prototype.checkNull = function(data, name) {
	if (data == null) {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	}
	return false
}
Vue.prototype.checkBlank = function(data, name) {
	if (data == null || data == "") {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	}
	return false
}
Vue.prototype.checkValidName = function(data, name) {
	if (data == null || data == "") {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	} else if (!/^[\u4e00-\u9fa5]{2,15}$/.test(data)) {
		uni.showToast({
			icon: "none",
			title: name + "内容不正确"
		})
		return true
	}
	return false
}
Vue.prototype.checkValidTel = function(data, name) {
	if (data == null || data == "") {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	} else if (!/^1[0-9]{10}$/.test(data)) {
		uni.showToast({
			icon: "none",
			title: name + "内容不正确"
		})
		return true
	}
	return false
}
Vue.prototype.checkValidEmail = function(data, name) {
	if (data == null || data == "") {
		uni.showToast({
			icon: "none",
			title: name + "不能为空"
		})
		return true
	} else if (!/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(data)) {
		uni.showToast({
			icon: "none",
			title: name + "内容不正确"
		})
		return true
	}
	return false
}
Vue.prototype.checkValidStartAndEnd = function(start, end) {
	let d1 = new Date("2000/01/01 " + start + ":00");
	let d2 = new Date("2000/01/01 " + end + ":00");
	if (d2.getTime() <= d1.getTime()) {
		uni.showToast({
			icon: "none",
			title: "结束时间必须大于开始时间"
		})
		return true
	}
	return false
}